package com.huawei.appmarket.service.usercenter.userinfo.view.activity;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.e;
import com.huawei.appgallery.foundation.ui.framework.fragment.LoadingFragment;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.framework.titleframe.title.BackTitle;
import com.huawei.appmarket.service.usercenter.userinfo.bean.AddressBean;
import com.huawei.appmarket.service.usercenter.userinfo.bean.AreaInfoQueryRes;
import com.huawei.appmarket.service.usercenter.userinfo.bean.ProvinceInfo;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import o.ayy;
import o.azb;
import o.cvt;
import o.der.g;
import o.dgm;
import o.dmi;
import o.dmp;
import o.dmq;
import o.Logger;
import o.ContentManager;
import o.ema;
import o.emh;
import o.emk;
import o.ewm.j;
import o.eyo;
import o.FragmentTransaction;

public class AddressListActivity extends FragmentActivity implements e {
    private ListView ˊॱ;
    protected RelativeLayout ˋॱ;
    private AddressBean ˏॱ;
    private Handler ͺ = new d();
    private List<AddressBean> ॱˊ;

    class AddressListAdapter extends BaseAdapter {
        private AddressListAdapter() {
        }

        public int getCount() {
            if (AddressListActivity.this.ॱˊ != null) {
                return AddressListActivity.this.ॱˊ.size();
            }
            return 0;
        }

        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view == null) {
                view = LayoutInflater.from(AddressListActivity.this).inflate(g.ʾ, null);
            }
            RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(o.der.d.ˏ);
            Context ˋ = ContentManager.getInstant().getContext();
            if (azb.ʼ(ˋ)) {
                azb.ˋ(relativeLayout);
            } else {
                azb.ˋ(relativeLayout, ˋ.getResources().getDimensionPixelOffset(o.der.b.ʽ), ˋ.getResources().getDimensionPixelOffset(o.der.b.ˋ));
            }
            AddressBean addressBean = (AddressBean) AddressListActivity.this.ॱˊ.get(i);
            if (addressBean != null) {
                TextView textView = (TextView) view.findViewById(o.der.d.ॱॱ);
                View findViewById = view.findViewById(o.der.d.ˊʻ);
                azb.ˋ(findViewById);
                setDivideLine(i, findViewById);
                ArrayList arrayList = (ArrayList) AddressListActivity.this.ˎ(addressBean);
                ImageView imageView = (ImageView) view.findViewById(o.der.d.ˋ);
                if (arrayList == null || arrayList.isEmpty()) {
                    imageView.setVisibility(8);
                } else {
                    imageView.setVisibility(0);
                }
                textView.setText(addressBean.ˊ);
                view.setTag(addressBean);
            }
            return view;
        }

        private void setDivideLine(int i, View view) {
            if (i == getCount() - 1) {
                view.setVisibility(8);
            } else {
                view.setVisibility(0);
            }
        }
    }

    static class a implements dmi {
        private WeakReference<AddressListActivity> ˏ;

        public a(AddressListActivity addressListActivity) {
            this.ˏ = new WeakReference(addressListActivity);
        }

        public void run() {
            ArrayList ˋ = emk.ˋ().ˋ(ContentManager.getInstant().getContext());
            AddressListActivity addressListActivity = (AddressListActivity) this.ˏ.get();
            if (addressListActivity != null) {
                Message obtain = Message.obtain();
                obtain.what = 1000;
                obtain.obj = ˋ;
                addressListActivity.ͺ.sendMessage(obtain);
            }
        }
    }

    static class b implements dmi {
        private List<ProvinceInfo> ˋ;
        private WeakReference<AddressListActivity> ˏ;

        public b(AddressListActivity addressListActivity, List<ProvinceInfo> list) {
            this.ˏ = new WeakReference(addressListActivity);
            this.ˋ = list;
        }

        public void run() {
            if (this.ˋ != null && !this.ˋ.isEmpty()) {
                emh.ˋ(this.ˋ);
                AddressListActivity addressListActivity = (AddressListActivity) this.ˏ.get();
                if (addressListActivity != null) {
                    ArrayList ˋ = emk.ˋ().ˋ((Context) addressListActivity);
                    Message obtain = Message.obtain();
                    obtain.what = 1000;
                    obtain.obj = ˋ;
                    addressListActivity.ͺ.sendMessage(obtain);
                }
            }
        }
    }

    class d extends Handler {
        final /* synthetic */ AddressListActivity ˋ;

        private d(AddressListActivity addressListActivity) {
            this.ˋ = addressListActivity;
        }

        public void handleMessage(Message message) {
            switch (message.what) {
                case 1000:
                    if (message.obj instanceof List) {
                        this.ˋ.ॱˊ = (List) message.obj;
                    }
                    this.ˋ.ॱॱ();
                    return;
                default:
                    return;
            }
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ayy.ˋ().ˎ(getWindow());
        getWindow().setBackgroundDrawableResource(o.der.a.ᐝ);
        if (bundle != null) {
            this.ˏॱ = (AddressBean) bundle.getParcelable("addresscSelect");
            return;
        }
        setContentView(g.ॱˋ);
        ॱ(getTitle());
        ॱˊ();
        Bundle extras = new SafeIntent(getIntent()).getExtras();
        if (extras != null) {
            Serializable serializable = extras.getSerializable("addresslist");
            if (serializable instanceof ArrayList) {
                this.ॱˊ = (ArrayList) serializable;
            }
        }
        if (this.ॱˊ == null || !this.ॱˊ.isEmpty()) {
            if (this.ॱˊ != null && !this.ॱˊ.isEmpty()) {
                ॱॱ();
            }
        } else if (emk.ˋ().ˎ()) {
            dmq.ˏ.ˊ(dmp.ˋ, new a(this));
        } else {
            ʼ();
        }
    }

    private void ॱॱ() {
        ͺ();
        ᐝ();
    }

    private void ͺ() {
        this.ˊॱ.setAdapter(new AddressListAdapter());
        this.ˊॱ.setOnItemClickListener(new OnItemClickListener(this) {
            final /* synthetic */ AddressListActivity ˏ;

            {
                this.ˏ = r1;
            }

            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                this.ˏ.ॱ(view);
            }
        });
    }

    private void ॱ(View view) {
        Object tag = view.getTag();
        if (tag instanceof AddressBean) {
            this.ˏॱ = (AddressBean) tag;
            ArrayList arrayList = (ArrayList) ˎ(this.ˏॱ);
            if (arrayList == null || arrayList.isEmpty()) {
                int ॱ = ॱ(this.ˏॱ.ˏ);
                Intent intent = new Intent();
                if (ॱ == 1124) {
                    intent.putExtra("addresscitySelect", this.ˏॱ);
                } else if (ॱ == 1125) {
                    intent.putExtra("addressdistrictSelect", this.ˏॱ);
                } else {
                    intent.putExtra("addressprovinceSelect", this.ˏॱ);
                }
                setResult(ॱ, intent);
                finish();
                return;
            }
            int ˏ = ˏ(this.ˏॱ.ˏ);
            Intent intent2 = new Intent();
            Bundle bundle = new Bundle();
            bundle.putSerializable("addresslist", arrayList);
            intent2.putExtras(bundle);
            intent2.setClass(this, AddressListActivity.class);
            try {
                startActivityForResult(intent2, ˏ);
            } catch (ActivityNotFoundException e) {
                Logger.ˋ("AddressListActivity", "ActivityNotFoundException :" + e.toString());
            }
        }
    }

    protected void ʼ() {
        this.ˋॱ.setVisibility(0);
        this.ˊॱ.setVisibility(8);
        Fragment loadingFragment = new LoadingFragment();
        FragmentTransaction ˊ = ˏॱ().ˊ();
        ˊ.ˏ(o.der.d.ᐝ, loadingFragment, "InfoGetLoadTag");
        ˊ.ˋ();
    }

    protected void ᐝ() {
        this.ˋॱ.setVisibility(8);
        this.ˊॱ.setVisibility(0);
    }

    private void ॱˊ() {
        this.ˊॱ = (ListView) findViewById(o.der.d.ʽ);
        this.ˋॱ = (RelativeLayout) findViewById(o.der.d.ᐝ);
    }

    protected void ॱ(CharSequence charSequence) {
        if (charSequence == null) {
            Logger.e("AddressListActivity", "error title.");
            return;
        }
        View findViewById = findViewById(j.ˇˊ);
        if (findViewById instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) findViewById;
            BaseTitleBean baseTitleBean = new BaseTitleBean();
            baseTitleBean.ॱ(charSequence.toString());
            View ˋ = new BackTitle(this, baseTitleBean).ˋ();
            if (ˋ != null) {
                viewGroup.setVisibility(0);
                viewGroup.addView(ˋ);
            }
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        bundle.putParcelable("addresscSelect", this.ˏॱ);
        super.onSaveInstanceState(bundle);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 == 1125) {
            intent.putExtra("addresscitySelect", this.ˏॱ);
            setResult(1124, intent);
            finish();
        } else if (i2 == 1124) {
            intent.putExtra("addressprovinceSelect", this.ˏॱ);
            setResult(1123, intent);
            finish();
        }
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }

    public boolean ˋ(TaskFragment taskFragment, com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        if (bVar.ˋ != null && bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0) {
            ResponseBean responseBean = bVar.ˋ;
            if (responseBean instanceof AreaInfoQueryRes) {
                dmq.ˏ.ˊ(dmp.ˋ, new b(this, ((AreaInfoQueryRes) responseBean).ˏ()));
            }
        } else if (taskFragment instanceof LoadingFragment) {
            LoadingFragment loadingFragment = (LoadingFragment) taskFragment;
            eyo ॱ = eyo.ॱ(bVar.ˊ, bVar.ˋ, null);
            loadingFragment.ˏ(ॱ.ˊ(), ॱ.ᐝ());
        }
        return false;
    }

    public void ˎ(TaskFragment taskFragment, List<cvt> list) {
        cvt o_ema = new ema();
        o_ema.setServiceType_(dgm.ˎ(this));
        list.add(o_ema);
    }

    private List<AddressBean> ˎ(AddressBean addressBean) {
        if (addressBean.ˏ == 1) {
            return emk.ˋ().ˎ(getApplicationContext(), 2, addressBean.ˋ, addressBean.ˎ);
        }
        if (addressBean.ˏ == 2) {
            return emk.ˋ().ˎ(getApplicationContext(), 3, addressBean.ˋ, addressBean.ˎ);
        }
        return null;
    }

    private int ˏ(int i) {
        if (i == 1) {
            return 1124;
        }
        if (i == 2) {
            return 1125;
        }
        return 0;
    }

    private int ॱ(int i) {
        if (i == 1) {
            return 1123;
        }
        if (i == 2) {
            return 1124;
        }
        return 1125;
    }
}
